package com.cms.recursoshumanos.ui.principal;

import com.cms.recursoshumanos.cache.UserInfoCache;
import com.cms.recursoshumanos.component.base.CustomMenuField;
import com.cms.recursoshumanos.container.ForegroundManager;
import com.cms.recursoshumanos.container.GridFieldManager;
import com.cms.recursoshumanos.container.TwoColumnFieldManager;
import com.cms.recursoshumanos.engine.ScreenEngine;
import com.cms.recursoshumanos.handler.ListaContactoScreenHandler;
import com.cms.recursoshumanos.handler.MyUserDetailScreenHandler;
import com.cms.recursoshumanos.handler.ListaTipoEventosScreenHandler;
import com.cms.recursoshumanos.ui.RecursosHumanosScreen;
import com.cms.recursoshumanos.utilities.Tool;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Ui;
import net.rim.device.api.ui.XYEdges;
import net.rim.device.api.ui.decor.BorderFactory;

/**
 * A class extending the MainScreen class, which provides default standard
 * behavior for BlackBerry GUI applications.
 */
public final class PantallaPrincipalScreen extends RecursosHumanosScreen
{
    /**
     * Creates a new MyScreen object
     */
	//static Utileria tools = new Utileria();

	private GridFieldManager gridFieldManager;
	CustomMenuField item1, 
					item2, 
					item3, 
					item4, 
					item5, 
					item6;
	
	
	public static PantallaPrincipalScreen instance = null;
	
	public static PantallaPrincipalScreen getInstance()
	{
		if (instance == null)
		{
			instance =  new PantallaPrincipalScreen();
		}
		return instance;

	}
	public PantallaPrincipalScreen() 
	{
		super(NO_VERTICAL_SCROLL | USE_ALL_HEIGHT );
		//setear_componenetes();
		setContent();
		
	}
	
	public void setContent() 
	{
		setTitle("Principal");
		
		ForegroundManager foreground = new ForegroundManager();
		
		TwoColumnFieldManager twoColumnManager = new TwoColumnFieldManager( Display.getWidth() / 2, USE_ALL_WIDTH );
        twoColumnManager.setBorder( BorderFactory.createBitmapBorder( new XYEdges( 10, 10, 10, 10 ), Bitmap.getBitmapResource( "border_simple_white.png" ) ) );
        twoColumnManager.setMargin( 10, 10, 10, 10 );
        twoColumnManager.setPadding( 6, 6, 6, 6 );
		
		gridFieldManager = new GridFieldManager(2, GridFieldManager.USE_ALL_HEIGHT|GridFieldManager.USE_ALL_WIDTH|GridFieldManager.FIELD_HCENTER|GridFieldManager.FIELD_VCENTER|GridFieldManager.FOCUSABLE);
		
		Font myFont = getFont().derive(Font.ITALIC, 6, Ui.UNITS_pt);
        gridFieldManager.setFont(myFont);
        
		item1 = new CustomMenuField("Informacion Personal", 
				Tool.getInstance().sizeImage(Bitmap.getBitmapResource("icons/User.png"), 
						Tool.getInstance().getImgWidth()+30, 
						Tool.getInstance().getImgHeight()+30).getBitmap(), 
				Tool.getInstance().sizeImage(Bitmap.getBitmapResource("icons/User_Focus.png"), 
						Tool.getInstance().getImgWidth()+30, 
						Tool.getInstance().getImgHeight()+30).getBitmap(), 
				myFont, CustomMenuField.FIELD_VCENTER|CustomMenuField.FIELD_HCENTER) 
		{
			protected boolean navigationClick(int status, int time)
			{
				MyUserDetailScreenHandler handler = new MyUserDetailScreenHandler();
	   			handler.getAllUserInfo(UserInfoCache.getInstance().getUsuario().getNombre_Usuario(),
	   								UserInfoCache.getInstance().getUsuario().getPassword());	
				return true;
			}
		};
		item2 = new CustomMenuField("Directorio Corporativo", 
				Tool.getInstance().sizeImage(Bitmap.getBitmapResource("icons/Contacto.png"), 
						Tool.getInstance().getImgWidth()+30, 
						Tool.getInstance().getImgHeight()+30).getBitmap(), 
				Tool.getInstance().sizeImage(Bitmap.getBitmapResource("icons/Contacto_Focus.png"), 
						Tool.getInstance().getImgWidth()+30, 
						Tool.getInstance().getImgHeight()+30).getBitmap(), 
				myFont, 
				CustomMenuField.FIELD_VCENTER|CustomMenuField.FIELD_HCENTER) 
		{
			protected boolean navigationClick(int status, int time)
			{
				ListaContactoScreenHandler handler = new ListaContactoScreenHandler();
				handler.getListaContacto(UserInfoCache.getInstance().getUsuario().getNombre_Usuario(),
															UserInfoCache.getInstance().getUsuario().getPassword());

				return true;
			}
		};
		item3 = new CustomMenuField("Eventos", 
				Tool.getInstance().sizeImage(Bitmap.getBitmapResource("icons/Evento.png"), 
						Tool.getInstance().getImgWidth()+30, 
						Tool.getInstance().getImgHeight()+30).getBitmap(), 
				Tool.getInstance().sizeImage(Bitmap.getBitmapResource("icons/Evento_Focus.png"), 
						Tool.getInstance().getImgWidth()+30, 
						Tool.getInstance().getImgHeight()+30).getBitmap(), 
				myFont, 
				CustomMenuField.FIELD_VCENTER|CustomMenuField.FIELD_HCENTER) 
		{
			protected boolean navigationClick(int status, int time)
			{
				ListaTipoEventosScreenHandler handler = new ListaTipoEventosScreenHandler();
	   			handler.getListaTipoEvento(UserInfoCache.getInstance().getUsuario().getNombre_Usuario(), 
	   					UserInfoCache.getInstance().getUsuario().getPassword());
        		return true;
			}
		};
		item4 = new CustomMenuField("Nomina", 
				Tool.getInstance().sizeImage(Bitmap.getBitmapResource("icons/Nomina.png"), 
						Tool.getInstance().getImgWidth()+30, 
						Tool.getInstance().getImgHeight()+30).getBitmap(), 
				Tool.getInstance().sizeImage(Bitmap.getBitmapResource("icons/Nomina_Focus.png"), 
						Tool.getInstance().getImgWidth()+30, 
						Tool.getInstance().getImgHeight()+30).getBitmap(), 
				myFont, 
				CustomMenuField.FIELD_VCENTER|CustomMenuField.FIELD_HCENTER) 
		{
			protected boolean navigationClick(int status, int time)
			{
				
				ScreenEngine.getInstance().goPantallaPrincipalNomina();
				return true;
			}
		};
		item5 = new CustomMenuField("Beneficios",
				Tool.getInstance().sizeImage(Bitmap.getBitmapResource("icons/Benefits.png"), 
						Tool.getInstance().getImgWidth()+30, 
						Tool.getInstance().getImgHeight()+30).getBitmap(), 
				Tool.getInstance().sizeImage(Bitmap.getBitmapResource("icons/Benefits_Focus.png"), 
						Tool.getInstance().getImgWidth()+30, 
						Tool.getInstance().getImgHeight()+30).getBitmap(), 
				myFont, 
				CustomMenuField.FIELD_VCENTER|CustomMenuField.FIELD_HCENTER) 
		{
			protected boolean navigationClick(int status, int time)
			{
				ScreenEngine.getInstance().goPantallaPrincipalBeneficios();
				return true;
			}
		};
		item6 = new CustomMenuField("Vacaciones", 
				Tool.getInstance().sizeImage(Bitmap.getBitmapResource("icons/Vacation.png"), 
						Tool.getInstance().getImgWidth()+30, 
						Tool.getInstance().getImgHeight()+30).getBitmap(), 
				Tool.getInstance().sizeImage(Bitmap.getBitmapResource("icons/Vacation_Focus.png"), 
						Tool.getInstance().getImgWidth()+30, 
						Tool.getInstance().getImgHeight()+30).getBitmap(), 
				myFont, 
				CustomMenuField.FIELD_VCENTER|CustomMenuField.FIELD_HCENTER) 
		{
			protected boolean navigationClick(int status, int time){

	   			ScreenEngine.getInstance().goVacacionesMainScreen();
				return true;
			}
		};
		
		item1.setMargin(30, 30, 30, 30);
		item2.setMargin(30, 30, 30, 30);
		item3.setMargin(30, 30, 30, 30);
		item4.setMargin(30, 30, 30, 30);
		item5.setMargin(30, 30, 30, 30);
		item6.setMargin(30, 30, 30, 30);
		
		gridFieldManager.add(item1);
		gridFieldManager.add(item2);
		gridFieldManager.add(item3);
		gridFieldManager.add(item4);
		gridFieldManager.add(item5);
		gridFieldManager.add(item6);
		
		
		twoColumnManager.add( gridFieldManager );
        
        foreground.add( twoColumnManager );
        add( foreground );

		int marginHeight = (Display.getHeight()-30-85-(85*2)-85)/3;
		if(marginHeight > 0)
			gridFieldManager.setMargin(marginHeight, 5, marginHeight, 5);
		else
			gridFieldManager.setMargin(5, 5, 5, 5);
		
		item1.setFocus();
	}
	
	
	
	
}
